package IO;

import org.junit.Test;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class IO上传 {
    public static void main(String[] args) {

    }

    @Test
    public void writeFile() {
        String filepath = "G:\\1.txt";
        FileOutputStream fileOutputStream = null;
        try {
//            new FileOutputStream(filepath) 创建方式  写入当前内容，会覆盖原来的内容
//            new FileOutputStream(filepath,true) 创建方式   写入内容   会添加到原来的内容
            fileOutputStream = new FileOutputStream(filepath, true);
            String s = "hello";
//            s.getBytes() 把字符串转成字节数组
            fileOutputStream.write(s.getBytes());
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                fileOutputStream.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
